package com.example.springbootproject;

import com.example.listener.MyListener;
import com.example.springbootproject.config.MyConfiguration;
import com.example.springbootproject.redis.RedisTest;
import com.example.springbootproject.servlet.MyServlet;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.boot.web.servlet.ServletListenerRegistrationBean;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;

import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.locks.Lock;

@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
@ServletComponentScan
public class SpringBootProjectApplication {

    public static void main(String[] args) {
//        ApplicationContext;
//        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(MyConfiguration.class);
        ConfigurableApplicationContext context = SpringApplication.run(SpringBootProjectApplication.class, args);
        RedisTest redisTest = context.getBean(RedisTest.class);
        redisTest.testRedis();

    }

//    ApplicationContext;
//    AtomicInteger;
//    Lock;
//    BeanFactory;
//    BeanDefinition;


    // 将自定义servlet 注册到容器中 添加注解@ServletComponentScan
    @Bean
    public ServletRegistrationBean<MyServlet> getMyServlet(){
        ServletRegistrationBean<MyServlet> registrationBean = new ServletRegistrationBean<>(new MyServlet());
        registrationBean.setLoadOnStartup(1);
        return registrationBean;
    }

    // 将自定义Listener注册到容器
    @Bean
    public ServletListenerRegistrationBean getMyListener(){
        ServletListenerRegistrationBean registrationBean = new ServletListenerRegistrationBean(new MyListener());
        return registrationBean;
    }

}
